package netty.util;

import test.PerformanceAnalyze;

import java.time.Instant;

public class TimeDelay {

    static TimeDelay timeDelay;

    static {
        timeDelay = new TimeDelay();
    }

    PerformanceAnalyze performanceAnalyze = new PerformanceAnalyze();

    public static TimeDelay getInstance() {
        return timeDelay;
    }

    public void analyze(byte[] msg){
        performanceAnalyze.delay(System.nanoTime() - Long.parseLong(new String(msg)));
        performanceAnalyze.meter();
    }

    public void analyzeHalf(Long time){
        performanceAnalyze.delay((System.nanoTime() - time)/2);
        performanceAnalyze.meter();
    }

    public void analyze(Long time){
        performanceAnalyze.delay(System.nanoTime() - time);
        performanceAnalyze.meter();
    }

    public void analyze(int nona){
        performanceAnalyze.delay((long) Instant.now().getNano() - nona);
        performanceAnalyze.meter();
    }

}
